package com.cloud.fim.gate.container.repository;

import com.cloud.fim.gate.container.Session;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2019-11-09 19:31
 */
public class InMemorySessionRepository implements SessionRepository {

    private Map<Integer, Session> connMap;

    public InMemorySessionRepository() {
        this.connMap = new ConcurrentHashMap<>();
    }


    /**
     * @param cid the channel id of user
     * @return
     */
    @Override
    public Session get(Integer cid) {
        return connMap.get(cid);
    }

    /**
     * add session
     *
     * @param cid     the channel id of user
     * @param session the session  of user
     */
    @Override
    public void add(Integer cid, Session session) {
        connMap.put(cid, session);
    }

    /**
     * @param cid
     */
    @Override
    public void remove(Integer cid) {
        connMap.remove(cid);
    }

    /**
     * clear
     */
    @Override
    public void removeAll() {
        connMap.clear();
    }
}
